package com.lanxin.oa.approve.controller;

import com.lanxin.bean.LcApproval;
import com.lanxin.bean.LcFlow;
import com.lanxin.oa.approve.service.FlowService;
import com.lanxin.util.PageBean;
import com.lanxin.util.TimeConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/flow")
public class FlowController extends TimeConverter {
    @Autowired
    private FlowService flowService;

    @RequestMapping("/listMyFlow")
    public ModelAndView listMyFlow(HttpSession session, LcApproval approval, Integer page, Integer pageSize) {
        PageBean pageBean = flowService.listMyFlow(page, pageSize,session,approval);
        ModelAndView mv = new ModelAndView();
        List<LcFlow> lcFlow = flowService.selectLcFlow();
        mv.addObject("pageBean", pageBean);
        mv.addObject("lcFlow",lcFlow);
        mv.addObject("approval", approval);
        mv.setViewName("../view/approve/myflow.jsp");
        return mv;
    }

    @RequestMapping("/approvalLog")
    public ModelAndView approvalLog(String docNo) {
        List<LcApproval> listApproval =flowService.listApprovalJiLu(docNo);
        ModelAndView mv = new ModelAndView();
        mv.addObject("listApproval", listApproval);
        mv.setViewName("../view/approve/approvejilu.jsp");
        return mv;
    }


    @RequestMapping("listMyApproval")
    public ModelAndView listMyApproval(HttpSession session, LcApproval approval, Integer page, Integer pageSize) {
        Integer empid= (Integer) session.getAttribute("empid");
        PageBean pageBean = flowService.listMyApproval(approval, empid, page, pageSize);
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageBean", pageBean);
        mv.addObject("approval", approval);
        mv.setViewName("../view/approve/myapprovedai.jsp");
        return mv;
    }

    @RequestMapping("toApproval")
    public ModelAndView toApproval(Integer oid) {
        LcApproval approval = flowService.approvalInfo(oid);
        List<LcApproval> listApproval = flowService.listApprovalByDocNo(approval.getDocNo());
        String docInfoUrl = flowService.docInfoUrl(approval.getDocid());
        ModelAndView mv = new ModelAndView();
        mv.addObject("listApproval", listApproval);
        mv.addObject("approval", approval);
        mv.addObject("docInfoUrl", docInfoUrl);
        mv.setViewName("../view/approve/doapproval.jsp");
        return mv;
    }


    @RequestMapping("doApproval")
    public String doApproval(LcApproval approval, HttpSession session) {
        Integer empid= (Integer) session.getAttribute("empid");
        flowService.doApproval(approval, empid);
        return "redirect:/flow/listMyApproval";
    }
}
